module ApplicationHelper
  def tag_if(condition, tag, *options, &block)
    content_tag(tag, *options, &block) if condition
  end

  def tag_unless(condition, tag, *options, &block)
    tag_if(!condition, tag, *options, &block)
  end

  %i(div li p a span).each do |tag|
    define_method "#{tag}_if" do |condition, *options, &block|
      tag_if(condition, tag, *options, &block)
    end
    define_method "#{tag}_unless" do |condition, *options, &block|
      tag_unless(condition, tag, *options, &block)
    end
  end
end
